<template>
	<view class="content with-tabbar ">
		<div class="fontS48 lh-72 font-weight mt-42 mb-30">选择求职期望</div>
		<div class="lh-144"></div>
		<scroll-view style="white-space: normal;" scroll-y>
			<div class="flex-center resumeItem mb-20" v-for="(item, index) in resumeList" :key="index"
				@click="editResume(item, index)">
				<div>
					<div class="fontS28 font-bold">{{ item.expectTypeName ? item.expectTypeName : '' }}</div>
					<div class="mt-10">{{ item.professionName ? item.professionName : '' }} {{ item.minSalary &&
						item.maxSalary ? item.minSalary + '元-' + item.maxSalary + '元' : '' }}</div>
					<div class="mt-10 fontS24 color-grey">{{ item.cityName ? item.cityName : '' }} {{
						item.industryNames ? '·' + item.industryNames : '' }}</div>
				</div>
				<div v-if="prePage" class=" ml-auto iconfont fontS40"
					:class="index == expectIndex ? 'icon-xuanzhong color-green' : 'icon-danxuankuang color-6d'"></div>
				<div v-else class="iconfont icon-youjiantou ml-auto"></div>

			</div>
			<div class="bg-fff pt-18 pb-18 pl-30 pr-30 lh-50 text-center bor-r16" @click="changeFile">
				继续上传（{{ resumeList.length }}/3）</div>

		</scroll-view>
		<div class="bottom" v-if="!prePage">
			<div class="submitBtn fontS26 " @click="toNext">生成在线简历
			</div>

		</div>
		<div class="bottom" v-if="flag">
			<div class="submitBtn fontS26 " @click="bindResum">添加求职期望
			</div>

		</div>



	</view>
</template>

<script>
import { resume, getResumeExpect, onLineResume, resumeExpectBind } from '@/api/resume'
const ossUploadFile = require("@/utils/ossupload/upload").ossUploadFile;
const api = require("@/api/api.js").api;
export default {
	computed: {
		userInfo() {
			console.log(this.$store.getters.userInfo)
			return this.$store.getters.userInfo || {};
		},
	},
	data() {
		return {
			baseUrl: getApp().globalData.baseUrl,
			postForm: {

			},
			formAll: {},
			resumeList: [],
			prePage: null,
			expectIndex: null,
			flag: false
		}
	},
	async onLoad(options) {
		if (options.page) {
			this.prePage = options.page
			await this.getonLineResume()
		}
		if (options.flag) {
			this.flag = options.flag
		}
	},
	async onShow() {
		await this.getResumeList()
	},
	methods: {
		async getonLineResume() {
			const { data } = await onLineResume()
			this.postForm = data

		},
		async getResumeList() {
			const { data } = await getResumeExpect()
			this.resumeList = data
		},
		async changeFile() {
			if (this.resumeList.length >= 3) {
				uni.showToast({
					title: '最多只能添加3个',
					icon: 'none'
				})
				return false;
			}
			uni.navigateTo({
				url: `/pages/resume/expect`
			})
		},
		async editResume(item, index) {
			if (!this.prePage) {
				uni.navigateTo({
					url: `/pages/resume/expect?id=${item.id}`
				})
			} else {
				this.expectIndex = index
			}
			this.$forceUpdate()

		},

		async toNext() {
			if (this.expectIndex === null) {
				uni.showToast({ title: '请先选择求职期望', icon: 'none' })
				return false;
			}
			const creat1 = JSON.parse(uni.getStorageSync('creat1Info'))
			const creat2 = JSON.parse(uni.getStorageSync('creat2Info'))
			const creat3 = JSON.parse(uni.getStorageSync('creat3Info'))
			const creat4 = JSON.parse(uni.getStorageSync('creat4Info'))
			const formAll = {
				...creat1, ...creat4,
				resumeEducationReqDto: creat3,
				resumeWorkReqDto: creat2,
				expectId: this.resumeList[this.expectIndex].id
			}
			const { data } = await resume(formAll)
			uni.removeStorageSync('creat1Info')
			uni.removeStorageSync('creat2Info')
			uni.removeStorageSync('creat3Info')
			uni.removeStorageSync('creat4Info')
			uni.redirectTo({
				url: `/pages/resume/success?resumeId=${this.postForm.resumeId}`
			})

		},
		async bindResum() {
			if (this.expectIndex === null) {
				uni.showToast({ title: '请先选择求职期望', icon: 'none' })
				return false;
			}
			const { code } = await resumeExpectBind({
				expectId: this.resumeList[this.expectIndex].id,
				resumeId: this.postForm.id
			})
			uni.navigateBack({
				delta: 1
			})


		}

	}
}
</script>

<style lang="less" scoped>
.content {
	display: flex;
	flex-direction: column;

	padding: 0 20upx;

}

.title {
	font-size: 20px;
	font-weight: bold;
	margin-bottom: 20px;
}

.resume-box {
	.resume-title {
		width: 200upx;
	}

	.form-cnt {
		width: calc(100% - 240upx);

	}

	.form-cnt1 {
		width: 100%;

		textarea {
			width: 100%;
			line-height: 50upx;
			text-align: justify;
		}

	}

	.resume-input {
		width: calc(100% - 200upx);

		input {
			width: 100%;
			height: 50upx;
			line-height: 50upx;
		}
	}
}

.profession-cover {
	width: 100%;
	height: 100vh;
	position: fixed;
	left: 0;
	bottom: 0;
	background: rgba(0, 0, 0, .3);
	z-index: 888888;
}

.profession-box {
	bottom: 0;
	left: 0;
	width: 100%;
	height: 600upx;
	background: #F7F7F7;
	position: fixed;
	z-index: 999999;

	.profession-left {
		width: 50%;
		text-align: center;
		background: #fff;


		div {
			line-height: 90upx;

			&.active {
				background: #F7F7F7;
			}

		}
	}

	.profession-right {
		background: #F7F7F7;
		width: 50%;
		padding-left: 20upx;

		div {
			line-height: 90upx;

		}

	}
}

.resumeItem {
	background: #fff;
	padding: 20upx 20upx;
	border-radius: 8rpx;
}

.bottom {
	padding-bottom: calc(constant(safe-area-inset-bottom) + 22upx);
	/*兼容 IOS<11.2*/
	padding-bottom: calc(env(safe-area-inset-bottom) + 22upx);
	/*兼容 IOS>11.2*/
}

.color-0d0 {
	color: #0D0D12;
}
</style>